<template>
    <div class="resource-manage">
    <div class="card-box">
        <div class="card-title">基本信息</div>
        <el-form ref="baseForm" :model="baseForm" class="form-wrap" size="small" :rules="baseForm_rules" label-position="top">
           <!-- <el-form-item label="物业编号" prop="propertyCode">
                <el-input maxlength="30" :readonly="!isAdd" v-model="baseForm.propertyCode" placeholder="请输入物业编号"></el-input>
            </el-form-item>-->
            <el-form-item label="物业名称" prop="propertyName">
                <el-input maxlength="30" v-model="baseForm.propertyName" placeholder="请输入物业名称"></el-input>
            </el-form-item>
            <el-form-item label="曾用名" prop="usedName">
                <el-input maxlength="30" placeholder="请输入曾用名" v-model="baseForm.usedName"></el-input>
            </el-form-item>
            <el-form-item label="所属项目" prop="projectId">
                <el-select @change="queryBuilding" v-model="baseForm.projectId" placeholder="请选择所属项目">
                    <el-option
                        v-for="item in projects"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="所属楼栋" prop="buildingId">
                <el-select :disabled="!isAdd" v-model="baseForm.buildingId" @change="queryFloor" placeholder="请选择所属楼栋">
                    <el-option
                        v-for="item in buildings"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item ref="roomUnitItem" label="所属单元" prop="roomUnit">
                <el-select :disabled="!isAdd" v-model="baseForm.roomUnit" placeholder="请选择所属单元" >
                    <el-option
                        v-for="item in roomUnits"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="所属楼层" prop="floor">
                <el-select :disabled="!isAdd" v-model="baseForm.floor" placeholder="请选择所属楼层">
                    <el-option
                        v-for="item in floors"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="物业类型" prop="projectType">
                <el-select v-model="baseForm.projectType" @change="changeProjectType" placeholder="请选择物业类型">
                    <el-option
                        v-for="item in propertyTypes"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="物业用途" prop="projectSubclassType">
                <el-select v-model="baseForm.projectSubclassType" prop="projectSubclassType" placeholder="请选择物业用途">
                    <el-option
                        v-for="item in useTypesFilter"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="实际用途" prop="actualType">
                <el-input maxlength="30" v-model="baseForm.actualType" placeholder="请输入实际用途"></el-input>
<!--                <el-select v-model="baseForm.actualType" placeholder="请选择实际用途">-->
<!--                    <el-option-->
<!--                        v-for="item in actualTypes"-->
<!--                        :key="item.value"-->
<!--                        :label="item.label"-->
<!--                        :value="item.value">-->
<!--                    </el-option>-->
<!--                </el-select>-->
            </el-form-item>
<!--            <el-form-item label="建筑面积(m²)" prop="buildingArea">-->
<!--                <el-input v-model="baseForm.buildingArea" placeholder="请输入建筑面积">-->
<!--                </el-input>-->
<!--            </el-form-item>-->
            <el-form-item label="分摊公用面积(m²)" prop="apportionedArea">
                <el-input v-model="baseForm.apportionedArea" placeholder="请输入分摊公用面积" @blur="handleAreaCompared">
                </el-input>
            </el-form-item>
            <el-form-item label="套内面积(m²)" prop="unitConstructionArea">
                <el-input v-model="baseForm.unitConstructionArea" placeholder="请输入套内面积" @blur="handleAreaCompared">
                </el-input>
            </el-form-item>
            <el-form-item label="物业管理单位（公司）" prop="manager">
                <el-input maxlength="30"  placeholder="请输入物业管理单位（公司" v-model="baseForm.manager" ></el-input>
            </el-form-item>
            <el-form-item label="土地使用期限" prop="serviceLife">
                <el-date-picker
                    v-model="baseForm.serviceLife"
                    type="date"
                    value-format="yyyy-MM-dd"
                    format="yyyy-MM-dd"
                    placeholder="选择日期"></el-date-picker>
            </el-form-item>
            <el-form-item label="经营情况" prop="operation">
                <el-select v-model="baseForm.operation" placeholder="请选择经营情况">
                    <el-option
                        v-for="item in operations"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value">
                    </el-option>
                </el-select>
            </el-form-item>
<!--            <el-form-item label="可用状态" prop="status">-->
<!--                <el-select v-model="baseForm.status" placeholder="请选择可用状态">-->
<!--                    <el-option-->
<!--                        v-for="item in roomUseStatus"-->
<!--                        :key="item.value"-->
<!--                        :label="item.label"-->
<!--                        :value="item.value">-->
<!--                    </el-option>-->
<!--                </el-select>-->
<!--            </el-form-item>-->
<!--            <el-form-item label="物业状态" prop="propertyStatus">-->
<!--                <el-select v-model="projectForm.propertyStatus" placeholder="暂无数据" disabled>-->
<!--                    <el-option-->
<!--                        v-for="item in propertyStatusList"-->
<!--                        :key="item.value"-->
<!--                        :label="item.label"-->
<!--                        :value="item.value">-->
<!--                    </el-option>-->
<!--                </el-select>-->
<!--            </el-form-item>-->
            <el-form-item label="物业来源" prop="propertySource">
                <el-select v-model="baseForm.propertySource" placeholder="请选择物业来源">
                    <el-option
                        v-for="item in propertySources"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="建构日期" prop="constructionTime">
                <el-date-picker
                    v-model="baseForm.constructionTime"
                    type="date"
                    value-format="yyyy-MM-dd"
                    format="yyyy-MM-dd"
                    placeholder="选择日期"></el-date-picker>
            </el-form-item>
            <el-form-item label="竣工日期" prop="endTime" disabled>
                <el-date-picker
                    v-model="projectForm.endTime"
                    type="date"
                    value-format="yyyy-MM-dd"
                    format="yyyy-MM-dd"
                    placeholder="暂无数据">
                </el-date-picker>
            </el-form-item>
            <el-form-item label="建构价款(元)" prop="suggestPrice">
                <el-input v-model="baseForm.suggestPrice" placeholder="请输入建构价款">
                    <template slot="suffix">元</template>
                </el-input>
            </el-form-item>
            <el-form-item label="管理权属" prop="manageUnit">
                <el-select v-model="baseForm.manageUnit" placeholder="请选择管理所">
                    <el-option
                        v-for="item in manageUnits"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value"></el-option>
                </el-select>
            </el-form-item>
            <!--<el-form-item label="街道" prop="roomStreet" >
                <el-select v-model="baseForm.roomStreet" filterable placeholder="请选择街道">
                    <el-option
                        v-for="item in streets"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value"
                    ></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="社区" prop="communityName" >
                <el-select v-model="baseForm.communityName" filterable placeholder="请选择社区">
                    <el-option
                        v-for="item in communityName"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value"
                    ></el-option>
                </el-select>
            </el-form-item>-->
            <el-form-item label="物业地址" prop="cityCode" class="full">
                <el-row :gutter="10">
                    <el-col :span="4">
                        <el-select placeholder="请选择市" v-model="baseForm.cityCode">
                            <el-option
                                v-for="item in cityAssembly"
                                :key="item.value"
                                :label="item.label"
                                :value="item.value">
                            </el-option>
                        </el-select>
                    </el-col>
                    <el-col :span="5">
                        <el-select placeholder="请选择区(县)" v-model="baseForm.countyCode" @change="handleChangeCountyCode">
                            <el-option
                                v-for="item in (this.baseForm.cityCode === '') ? [] : districtCollection"
                                :key="item.value"
                                :label="item.label"
                                :value="item.value">
                            </el-option>
                        </el-select>
                    </el-col>
                    <el-col :span="5">
                        <el-select placeholder="请选择街道(乡)" v-model="baseForm.roomStreet" @change="handleChangeStreet">
                            <el-option
                                v-for="item in (this.baseForm.countyCode === '') ? [] : streets"
                                :key="item.value"
                                :label="item.label"
                                :value="item.value">
                            </el-option>
                        </el-select>
                    </el-col>
                    <el-col :span="5">
                        <el-select placeholder="请选择社区(村)" v-model="baseForm.communityName">
                            <el-option
                                v-for="item in (this.baseForm.roomStreet === '') ? [] : communityNameStreet"
                                :key="item.value"
                                :label="item.label"
                                :value="item.value">
                            </el-option>
                        </el-select>
                    </el-col>
                    <el-col :span="5">
                        <el-input v-model="baseForm.address" placeholder="请选择道路及门牌号">
                        </el-input>
                    </el-col>
                </el-row>
            </el-form-item>
            <el-form-item label="地图坐标" prop="mapCoordinates" style="position: relative;">
                <button type="button" @click="$refs.positionDialog.show()" style="position: absolute;top: -38px;left: 70px;">选择</button>
                <el-input v-model.number="baseForm.mapCoordinates" placeholder="请输入地图坐标" suffix-icon="el-icon-map-location"></el-input>
            </el-form-item>
            <!--<div class="col-two">
                <city-select ref="citySelectForm" :areaCode.sync="baseForm.areaCode"  @changeArea="changeArea"></city-select>
            </div>
            <el-form-item label="详细地址" prop="address">
                <el-input maxlength="50" v-model="baseForm.address" placeholder="请输入详细地址">
                </el-input>
            </el-form-item>-->
            <el-form-item label="VR地址" prop="remarks">
                <el-input maxlength="100"  v-model="baseForm.vrUrl" placeholder="请输入VR地址">
                </el-input>
            </el-form-item>
            <el-form-item label="备注" prop="remarks" class="full">
                <el-input maxlength="200" v-model="baseForm.remarks" placeholder="请输入备注">
                </el-input>
            </el-form-item>
        </el-form>
        <!-- 地图坐标选择弹窗 -->
        <positionDialog ref="positionDialog" @changeMessage="resetPosition"/>
    </div>
    </div>
</template>

<script>
    import citySelect from "@/views/property-info-sys/project-manage/components/citySelect"
    import { doubleValidate} from '~/utils/validate.js'
    import {getAllProject,getAddress} from "@/views/property-info-sys/project-manage/api/project_manage"
    import {getBuildAddress} from "@/views/property-info-sys/building-manage/api/building"
    import positionDialog from "@/components/positionDialog"
    import { getChild, buildBuildingUnit,validateRoomCode,validateRoomName } from "@/views/property-info-sys/property-manage/api/room"
    import { getDict } from '~/utils'
    import {mapGetters} from "vuex";

    export default {
        name: "base-info",
        components:{
            citySelect,
            positionDialog
        },
        data() {
            let validateRoomCode = (rule, value, callback) => {
                if (!value) {
                    return callback(new Error('物业编号不能为空！'));
                }
                this.validateOnly(value, callback)
            };
            let validateRoomName = (rule, value, callback) => {
                if (!value) {
                    return callback(new Error('物业名称不能为空！'));
                }
                this.validateNameOnly(value, callback)
            };
            return {
                buildingCascadeInit: true,
                floorCascadeInit: true,
                baseForm: {
                    propertyCode: '',
                    propertyName: '',
                    projectId: '',
                    buildingId: '',
                    roomUnit: '',
                    floor: '',
                    propertyType:'',
                    useType:'',
                    actualType: '',
                    buildingArea: '',
                    unitConstructionArea: '',
                    operation: '',
                    status: '',
                    propertySource: '',
                    constructionTime: '',
                    suggestPrice: '',
                    remarks: '',
                    provinceCode: '',
                    manageUnit: '',
                    mapCoordinates:'',//所在地图坐标
                    cityCode: '',
                    countyCode: '',
                    roomStreet: '',
                    address: '',
                    communityName: '',
                    areaCode: '',
                    areaName: '',
                    usedName: ''

                },
                projectForm: {
                    initialType: '',
                    planUse: '',
                    parkingSpotNum: '',
                    totalBuildings: '',
                    useLandArea: '',
                    floorSpace: '',
                    useArea: '',
                    unmanagedArea: '',
                    managedArea: '',
                    noApportionedArea: '',
                    belong: '',
                    obligee: '',
                    occupier: '',
                    manager: '',
                    serviceLife: '',
                    ownershipNature: '',
                    propertyStatus: '',
                    endTime: '',
                    areaCode: '',
                    areaName: '',
                },
                baseForm_rules: {
                    // propertyCode: [
                    //     { required: true, validator: validateRoomCode, trigger: 'blur' }
                    // ],
                    propertyName: [
                        { required: true, validator: validateRoomName, trigger: 'blur' }
                    ],
                    projectId: [
                        { required: true, message: "请选择所属项目", trigger: "blur" },
                    ],
                    buildingId: [
                        { required: true, message: "请选择所属楼栋", trigger: "blur" },
                    ],
                    roomUnit: [
                        { required: true, message: "请选择所属单元", trigger: "blur" },
                    ],
                    floor: [
                        { required: true, message: "请选择所属楼层", trigger: "blur" },
                    ],
                    projectType: [
                        { required: true, message: "请选择物业类型", trigger: "blur" },
                    ],
                    projectSubclassType: [
                        { required: true, message: "请选择物业用途", trigger: "blur" },
                    ],
                    actualType: [
                        { required: true, message: "请选择实际用途", trigger: "blur" },
                        { min: 0, max: 30, message: "长度在0-30个字符串", trigger: "blur" },
                    ],
                    buildingArea: [
                        { required: true, message: "请输入建筑面积", trigger: "blur" },
                        { validator: doubleValidate, trigger: "change" },
                    ],
                    unitConstructionArea: [
                        { required: true, message: "请输入套内面积", trigger: "blur" },
                        { validator: doubleValidate, trigger: "change" },
                    ],
                    apportionedArea:[
                        { required: true, message: "请输入套内面积", trigger: "blur" },
                        { validator: doubleValidate, trigger: "change" },
                    ],
                    operation: [
                        { required: true, message: "请选择经营情况", trigger: "blur" },
                    ],
                    // status: [
                    //     { required: true, message: "请选择可用状态", trigger: "blur" },
                    // ],
                    propertySource: [
                        { required: true, message: "请选择物业来源", trigger: "blur" },
                    ],
                    constructionTime: [
                        { required: false, message: "请输入构建日期", trigger: "blur" },
                    ],
                    usedName: [
                        { required: false, message: "请输入曾用名", trigger: "blur" },
                        { min: 0, max: 30, message: "长度在0-30个字符串", trigger: "blur" }
                    ],
                    /*communityName: [
                        { required: true, message: "请选择社区", trigger: "blur" },
                    ],
                    roomStreet: [
                        { required: true, message: "请选择街道", trigger: "blur" },
                    ],*/
                    cityCode: [
                        { required: true, message: "请选择地址", validator: (rules, value, callback) => {
                                //区县
                                let county = this.baseForm.countyCode
                                //   街道
                                let street = this.baseForm.roomStreet
                                //   社区
                                let community = this.baseForm.communityName
                                //   道路及门牌号
                                let address = this.baseForm.address
                                if(!value || !county || !street || !community || !address){
                                    return callback(new Error("物业地址不能为空"))
                                }
                                return callback()
                            },  trigger: "blur" },
                    ],
                    manageUnit: [
                        { required: true, message: "请选择管理权属", trigger: "blur" },
                    ],
                    suggestPrice: [
                        { required: false, message: "请输入构建价款", trigger: "blur" },
                        { validator: doubleValidate, trigger: "change" },
                    ],
                    /* initialType: [
                       { required: true, message: "请选择初始类别", trigger: "blur" }
                   ],
                   planUse: [
                       { required: true, message: "请选择规划用途", trigger: "blur" },
                       { min: 0, max: 30, message: "长度在0-30个字符串", trigger: "blur" }
                   ],
                   parkingSpotNum: [
                       { required: true, message: "请输入停车位数", trigger: "blur" }
                   ],
                   totalBuildings: [
                       { required: true, message: "请输入总栋数", trigger: "blur" }
                   ],
                   useLandArea: [
                       { required: true, message: "请输入用地面积", trigger: "blur" },
                       { validator: doubleValidate, trigger: "change" }
                   ],
                   floorSpace: [
                       { required: true, message: "请输入占地面积", trigger: "blur" },
                       { validator: doubleValidate, trigger: "change" }
                   ],
                   useArea: [
                       { required: true, message: "请输入使用面积", trigger: "blur" },
                       { validator: doubleValidate, trigger: "change" }
                   ],
                   unmanagedArea: [
                       { required: true, message: "请输入非经营面积", trigger: "blur" },
                       { validator: doubleValidate, trigger: "change" }
                   ],
                   managedArea: [
                       { required: true, message: "请输入经营面积", trigger: "blur" },
                       { validator: doubleValidate, trigger: "change" }
                   ],
                   noApportionedArea: [
                       { required: true, message: "请输入不分摊面积", trigger: "blur" },
                       { validator: doubleValidate, trigger: "change" }
                   ],
                   belong: [
                       { required: true, message: "请选择物业权属", trigger: "blur" },
                   ],
                   obligee: [
                       { required: true, message: "请输入权利人", trigger: "blur" },
                       { min: 0, max: 30, message: "长度在0-30个字符串", trigger: "blur" }
                   ],
                   ownershipNature: [
                       { required: true, message: "请选择权利性质", trigger: "blur" }
                   ],
                   propertyStatus: [
                       { required: true, message: "请选择物业状态", trigger: "blur" }
                   ],
                   endTime: [
                       { required: true, message: "请选择竣工日期", trigger: "blur" }
                   ],*/
                },
               /* cityRules: {
                    provinceCode: [
                        { required: true, message: "请选择", trigger: "blur" },
                    ],
                    cityCode: [
                        { required: true, message: "请选择", trigger: "blur" },
                    ],
                    countyCode: [
                        { required: true, message: "请选择", trigger: "blur" },
                    ]
                },*/
                projects: [],
                buildings: [],
                roomUnits: [],
                floors: [],
                propertyTypes: [],
                useTypes: [],
                actualTypes:[],
                operations:[],
                roomUseStatus:[],
                propertySources:[],
                communityNames: [],
                communityNameStreet:[],
                streets: [],
                manageUnits:[],
                isAdd: true,
                planUses: [],
                initialTypes: [],
                belongs: [],
                ownershipNatureTypes: [],
                propertyStatusList: [],
                useTypesFilter:[]
            }
        },
        created() {
            getAllProject().then(rep => {
                let projectData = rep.data.data
                if(projectData){
                    this.projects = projectData.map( p => {
                        return {label: p.projectName, value: p.projectId}
                    })
                }
            })
            this.handleGetAddress(this.projectId)
            this.propertyTypes = getDict('property_types') //物业类型
            this.useTypes = getDict('property_use_types') //物业用途
            this.actualTypes = getDict('property_actual_types')
            this.operations = getDict('property_operations')
            this.roomUseStatus = getDict('room_use_status')
            this.propertySources = getDict('property_source')
            this.communityNames = getDict('community_names')
            this.streets = getDict('streets')
            this.manageUnits = getDict('administrative_office')
            this.planUses = getDict('plan_uses')
            this.belongs = getDict('belongs')
            this.ownershipNatureTypes = getDict('asset-ownership-nature')
            this.propertyStatusList = getDict('room_status')
            this.initialTypes = getDict('project_init_type')
        },
        methods: {
            //jiaj 根据物业类型，获取对应的物业用途
            changeProjectType(val){
                this.baseForm.projectSubclassType = ''
                //重置物业用途
                this.useTypesFilter = []
                if(val){
                    //过滤物业用途
                    this.useTypesFilter = this.useTypes.filter(ut => ut.value.indexOf(val) == 0)
                }
            },
            updateInit(data){
                this.isAdd = false
                this.baseForm = data
                this.initCommunityName();
                this.baseForm.cityCode = this.baseForm.areaCode.split('-')[0]
                this.baseForm.countyCode = this.baseForm.areaCode.split('-')[1]
                this.queryBuilding()
                this.queryFloor()

            },
            //地址选择器回调函数，
            changeArea(areaName, areaCode){
                this.baseForm.areaName = areaName
                this.baseForm.areaCode = areaCode
            },
            queryBuilding(){
                if(!this.buildingCascadeInit){
                    this.baseForm.buildingId = ''
                }
                this.buildingCascadeInit = false

                getChild(this.baseForm.projectId, '2').then( rep => {
                    let building = rep.data.data
                    if(building.treeNode){
                        this.buildings = building.treeNode.map(b => {
                            return {label: b.label, value: b.nodeId}
                        })
                        if(this.buildings.length > 0){
                            //默认第一个
                            this.baseForm.buildingId = this.buildings[0].value
                            this.queryFloor()
                        }
                    }
                })
                if (this.isAdd === true) {
                    this.handleGetAddress(this.baseForm.projectId)
                }
            },
            queryFloor(){
                //判断级联初始化标识，是否需要重置
                if(!this.floorCascadeInit){
                    this.baseForm.floor = ''
                    this.baseForm.roomUnit = ''
                }
                this.floorCascadeInit = false
                //获取单元
                buildBuildingUnit(this.baseForm.buildingId).then(rep => {
                    this.roomUnits = rep.data.data
                    if(this.roomUnits.length > 0){
                        this.baseForm_rules.roomUnit = [{ required: true, message: "请选择", trigger: "blur" }]

                        //默认第一个单元
                        this.baseForm.roomUnit = this.roomUnits[0].value
                    }else{
                        this.baseForm_rules.roomUnit = [{ required: false, trigger: "blur" }]
                    }
                })


                //获取所有楼层
                getChild(this.baseForm.buildingId, '3').then( rep => {
                    let floors = rep.data.data
                    if(floors.treeNode){
                        this.floors = floors.treeNode.map(b => {
                            return {label: b.label+'层', value: b.nodeId}
                        })
                        if(this.floors.length > 0){
                            //找地上层，没有则默认第一个
                            let gFloor = this.floors.find(f => f.label.indexOf('-') === -1);
                            if(gFloor){
                                this.baseForm.floor = gFloor.value
                            }else{
                                this.baseForm.floor = this.floors[0].value
                            }
                        }
                    }
                })

                //    楼栋地址回显
                // getBuildAddress(this.baseForm.buildingId).then(rep => {
                //     let repData = rep.data.data
                //     if(repData){
                //         this.baseForm.areaCode = repData.areaCode
                //         this.baseForm.areaName = repData.areaName
                //         this.baseForm.address = repData.address
                //         //经纬度
                //         this.baseForm.mapCoordinates =  repData.geographicCoordinates
                //         //街道
                //         this.baseForm.roomStreet = repData.buildStreet
                //         //社区
                //         this.baseForm.communityName = repData.communityName
                //         //管理权属
                //         this.baseForm.manageUnit = repData.manageUnit
                //         this.$forceUpdate()
                //     }
                // })

            },
            //验证房源编号是否存在
            validateOnly(value, callback){
                validateRoomCode({"roomCode": value, "roomId": this.baseForm.roomId}).then(rep => {
                    let vr = rep.data.data
                    if (vr === 0) {
                        return callback();
                    } else {
                        return callback(new Error("物业编号已存在， 请重新输入"));
                    }
                }).catch(e => {
                    console.log(e)
                })
            },
            //验证房源名称是否存在
            validateNameOnly(value, callback){
                validateRoomName({"roomName": value, "roomId": this.baseForm.roomId}).then(rep => {
                    let vr = rep.data.data
                    if (vr === 0) {
                        return callback();
                    } else {
                        return callback(new Error("物业名称已存在， 请重新输入"));
                    }
                }).catch(e => {
                    console.log(e)
                })
            },
            // 监听地图坐标监听
            resetPosition(data){
                let position = JSON.parse(data)
                if(position.length) {
                    // this.baseForm.longitude = position[0]
                    // this.baseForm.latitude = position[1]
                    this.baseForm.mapCoordinates = position.join(',')
                }
            },
            // hxf-0915-套内面积失焦校验
            handleAreaCompared() {
                this.baseForm.buildingArea = Number(this.baseForm.unitConstructionArea) + Number(this.baseForm.apportionedArea)
                // if (Number(this.baseForm.unitConstructionArea) > Number(this.baseForm.buildingArea)) {
                //     this.$message.error('套内面积不能大于建筑面积！')
                //     this.baseForm.unitConstructionArea = ''
                // }
            },
            // hxf-1010-区改变清空街道和社区
            handleChangeCountyCode() {
                this.baseForm.roomStreet = ''
                this.baseForm.communityName = ''
                this.$forceUpdate()
            },
            // hxf-1010-街道改变清空社区
            handleChangeStreet() {
                this.$forceUpdate()
                this.baseForm.communityName = ''
                this.initCommunityName()
            },
            // hxf-1012-获取项目信息
            handleGetAddress(id) {
                getAddress(id).then(res => {
                    if (res.data.code === 0 && res.data.data !== null) {
                        this.projectForm = res.data.data
                        if (this.isAdd === true) {
                            this.baseForm.areaCode = res.data.data.areaCode
                            this.baseForm.areaName = res.data.data.areaName
                            this.baseForm.cityCode = this.baseForm.areaCode.split('-')[0]
                            this.baseForm.countyCode = this.baseForm.areaCode.split('-')[1]
                            this.baseForm.roomStreet = res.data.data.projectStreet
                            this.baseForm.communityName = res.data.data.communityName
                            this.baseForm.address = res.data.data.addressInfo
                            this.baseForm.mapCoordinates =  res.data.data.mapCoordinates
                            this.baseForm.manageUnit =  res.data.data.manageUnit
                        }
                        this.initCommunityName();
                    } else {
                        this.projectForm = {}
                        this.baseForm.cityCode = this.cityAssembly[0].value
                        this.baseForm.countyCode = ''
                        this.baseForm.roomStreet = ''
                        this.baseForm.communityName = ''
                        this.baseForm.address = ''
                    }
                })
            },
            initCommunityName(){
                this.communityNameStreet.length = 0;
                let selectStreet = this.baseForm.roomStreet
                console.log("选择街道："+selectStreet)
                if(selectStreet != '' &&  this.communityNames != null &&  this.communityNames.length > 0){
                    this.communityNameStreet = this.communityNames.filter(cn => cn.value.indexOf(selectStreet) != -1)
                }
            },
            // hxf-1015-回显时对应value显示label
            getCardTypeValue(num, sum){
                let arr = sum.filter(e=>e.value === num)
                if (arr.length > 0) {
                    return arr[0].label
                } else {
                    return num
                }
            }
        },
        computed: {
            ...mapGetters({
                cityAssembly: 'getCityAssembly',
                districtCollection: 'getDistrictCollection',
            })
        },
        props: ['projectId']
    }
</script>

<style scoped lang='scss'>


    @include formWrap(2);

</style>
